package com.crscd.ai.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 *
 * @description:
 * @author: liuziyang
 * @since: 9/29/25 4:50 PM
 * @modifiedBy:
 * @version: 1.0
 */
@RestController
public class ChatClientController {
  private final ChatClient chatClient;

  public ChatClientController(ChatModel dashscopeChatModel) {
    this.chatClient = ChatClient.builder(dashscopeChatModel).build();
  }

  @GetMapping("/chatclient/doChat")
  public String doChat(@RequestParam(name = "msg", defaultValue = "2加9等于几") String msg) {
    return chatClient.prompt().user(msg).call().content();
  }
}
